<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>11_RegExp-正则规则的描点</title>
</head>
<body>

  <script>
    const str = "My name is RegExp, I am 18 years old. I am a student."

    // 字符串方法
    if (str.startsWith("My")) {
      console.log("my starts with my");
    }
    if (str.endsWith("student.")) {
      console.log("my ends with student.");
    }

    // 正则方法
    const reg = /RegExp/
    if (reg.test(str)) {
      console.log("RegExp is in str");
    }

    // 正则方法- 开头
    if (/^My/i.test(str)) {
      console.log("正则方法- 开头 my starts with my");
    }

    // 正则方法- 结尾
    if (/student.$/i.test(str)) {
      console.log("正则方法- 结尾 my ends with student.");
    }

    // 字符串方法
    if (str.includes("RegExp")) {
      console.log("RegExp is in str");
    }

    // 字符串方法
    if (str.indexOf("RegExp") !== -1) {
      console.log("RegExp is in str");
    }

  </script>
  
</body>
</html>